<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class cliente_x_reservaM extends CI_Model {

    public function __construct() {
        $this->load->database();
    }

    public function cargarHuespedes($idReserva) {
        $query = "SELECT c.* from cliente c, cliente_x_reserva cr
            where c.id_cliente=cr.id_cliente AND cr.id_reserva='$idReserva' AND 
            cr.id_establecimiento='" . $_SESSION["establecimiento"]["id_establecimiento"] . "' ORDER BY c.apellido";
      //  echo $query;
        return $this->db->query($query)->result();
    }

    public function registrarClinteEnReserva($idReserva, $idCliente) {
        $query = "INSERT INTO cliente_x_reserva VALUES('$idReserva','$idCliente','{$_SESSION["establecimiento"]["id_establecimiento"]}')";
       echo $query;
        return $this->db->query($query);
    }

    public function existeClienteEnReserva($idReserva, $idCliente) {
        $query = "SELECT count(*) cantidad FROM cliente_x_reserva where id_reserva='$idReserva' AND id_cliente='$idCliente'";
        return $this->db->query($query)->result();
    }

    public function eliminarClienteDeReserva($idReserva, $idCliente) {
        $query = "DELETE FROM cliente_x_reserva where id_reserva='$idReserva' AND id_cliente='$idCliente' AND id_establecimiento='{$_SESSION["establecimiento"]["id_establecimiento"]}'";
        echo $query;
        return $this->db->query($query);
    }
    public function contarHuespedes($idReserva){
        $query = "SELECT COUNT(*) cantidad FROM cliente_x_reserva where id_reserva='$idReserva'";
        return $this->db->query($query)->result();
    }

}